package com.zzx.threekingdom.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

public class HealthView extends View
{
    public int mHealth = 0;
    public int mHealthMax = 0;
    
    public HealthView(Context context)
    {
        this(context, (AttributeSet)null);
    }
    public HealthView(Context context, AttributeSet attrs)
    {
        this(context, attrs, 0);
    }
    public HealthView(Context context, AttributeSet attrs, int defStyle)
    {
        super(context, attrs, defStyle);
    }
    
    public void setHealth(int health)
    {
        mHealth = health;
        invalidate();
    }
    
    public void setHealthMax(int healthMax)
    {
        mHealthMax = healthMax;
        invalidate();
    }
    public void clearView()
    {
        setHealthMax(0);
        setHealth(0);
    }
    
    
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
    {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        setMeasuredDimension(100, 20);
    }
    
    @Override
    protected void onDraw (Canvas canvas)
    {
        Paint paint = new Paint();
        
        int cx = 10;
        int count = 0;
        paint.setColor(Color.RED);
        for(count = 0;count < mHealthMax;count++)
        {
            canvas.drawCircle(cx, 10, 8, paint);
            cx += 20;
        }
        cx = 10;
        paint.setColor(Color.YELLOW);
        for(count = 0;count < mHealth;count++)
        {
            canvas.drawCircle(cx, 10, 8, paint);
            cx += 20;
        }
    }
}
